package com.yun.algorithmproblem.huaweiod;

public class TVL {

    public void TLV(String s,String target) {
        char[] ch = s.toCharArray();
        int i = 0;
        int p = 0;
        int tag=0;
        int len = 0;
        int countLen=0;
        int lastTag=0;
        int length=ch.length;
        while (i < length) {
            if(i-p>length-3){
                System.out.println(false + " " + 0 + " " + "null");
                return;
            }
            if (0 <= p && p <= 2) {
                if (ch[i] < '0' || '9' < ch[i]) {
                    System.out.println(false + " " + 0 + " " + "null");
                    return;
                }
                p++;
            }else if(p==3){
                if (ch[i] < '0' || '9' < ch[i]) {
                    System.out.println(false + " " + 0 + " " + "null");
                    return;
                }
                tag=(ch[i-3]-'0')*10+ch[i-2]-'0';
                len=(ch[i-1]-'0')*10+ch[i]-'0';
                if(length-i<=len){
                    System.out.println(false + " " + 0 + " " + "null");
                    return;
                }
                StringBuilder sb=new StringBuilder();
                for (int j = 0; j < len; j++) {
                    i++;
                    sb.append(ch[i]);
                }
                if(sb.toString().contains(target)){
                    lastTag=tag;
                }
                countLen++;
                p=0;
            }
            i++;
        }
        System.out.println(true+" "+countLen+" "+lastTag);
    }
}
